package com.basic.library.utils;


import android.app.Activity;
import android.app.Dialog;
import android.widget.TextView;

import com.basic.library.R;


public class LoadingDialog {
    boolean isCancelable = true;
    private Dialog waitDialog = null;

    Activity activity;

    public LoadingDialog(Activity activity) {
        this.activity = activity;
        waitDialog = new Dialog(activity, androidx.appcompat.R.style.Theme_AppCompat_Light_Dialog);
        waitDialog.setContentView(R.layout.base_loading_dialog);
        waitDialog.setCancelable(isCancelable);
        waitDialog.setCanceledOnTouchOutside(false);
    }

    public void show() {
        if (waitDialog != null && !activity.isFinishing()) {
            TextView tv = waitDialog.findViewById(R.id.tv_loading_msg);
            tv.setText("加载中...");
            waitDialog.show();
        }
    }

    public void show(String msg) {
        if (waitDialog != null && !activity.isFinishing()) {
            TextView tv = waitDialog.findViewById(R.id.tv_loading_msg);
            tv.setText(msg + "...");
            waitDialog.show();
        }
    }

    public void cancel() {
        if (waitDialog != null && waitDialog.isShowing()) {
            waitDialog.cancel();
        }
    }

    public void dismiss() {
        if (waitDialog != null && waitDialog.isShowing()) {
            waitDialog.dismiss();
        }
    }

    public void setTitle(String title) {
        waitDialog.setTitle(title);
    }


}
